using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Solaris.Models;
using Solaris.Networking;
using Solaris.Screens;
using TomShane.Neoforce.Controls;

namespace Solaris
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class SolarisGame : Game
    {
        private readonly GraphicsDeviceManager mGraphics;
        private readonly OldScreenManager mScreenManager;

        private readonly Camera mCamera;

        // some gui
        public static Manager WindowManager;
        //private Window mWindow;
        //private Button mButton;

        public SolarisGame()
        {
            mGraphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            // Basic setup of the game window.
            IsMouseVisible = true;
            IsFixedTimeStep = false;
            mGraphics.PreferredBackBufferWidth = 800;
            mGraphics.PreferredBackBufferHeight = 600;
            mGraphics.SynchronizeWithVerticalRetrace = false;

            // Create screen manager.
            mScreenManager = new OldScreenManager(this);

            Components.Add(mScreenManager);
            Components.Add(new MessageDisplayComponent(this));
            Components.Add(new GamerServicesComponent(this));
            

            // Create an instance of manager using Default skin. We set the fourth parameter to true,
            // so the instance of manager is registered as an XNA game component and methods
            // like Initialize(), Update() and Draw() are called automatically in the game loop.
            // If you set this parameter to false, you have to call Manager.Initialize(), 
            // Manager.Update() and Manager.Draw() manually in their respective overriden methods
            // of the game class.
            // If you use two-parameter constructor, Default skin is used and manager is registered.
            WindowManager = new Manager(this, mGraphics, "Default", true);

            // Setting up the shared skins directory
            WindowManager.SkinDirectory = @"..\..\..\..\Skins\";
            
            
            // Listen for invite notification events.
            NetworkSession.InviteAccepted += (sender, e)
                => NetworkSessionComponent.InviteAccepted(mScreenManager, e);

            // To test the trial mode behavior while developing your game,
            // uncomment this line:

            // Guide.SimulateTrialMode = true;

            
        }

        protected override void Initialize()
        {
            base.Initialize();

            // If you have specified register parameter for the Manager to false put
            WindowManager.Initialize();                   
        }

        protected override void BeginRun()
        {
            // Activate the first screens.
            mScreenManager.AddScreen(new MainMenuScreen(), null);

            base.BeginRun();
        }


        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            mGraphics.GraphicsDevice.Clear(Color.Black);

            // The real drawing happens inside the screen manager component.
            base.Draw(gameTime);
        }
    }
}
